<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"movie0125.gitee.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="LFS学习笔记（三）">
<meta property="og:type" content="article">
<meta property="og:title" content="lfs-notebook-03">
<meta property="og:url" content="https://movie0125.gitee.io/2021/05/13/lfs-notebook-03/index.html">
<meta property="og:site_name" content="Movie Blog">
<meta property="og:description" content="LFS学习笔记（三）">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-05-13T00:59:57.000Z">
<meta property="article:modified_time" content="2021-05-13T02:43:26.279Z">
<meta property="article:author" content="Movie">
<meta property="article:tag" content="LFS">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://movie0125.gitee.io/2021/05/13/lfs-notebook-03/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>lfs-notebook-03 | Movie Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Movie Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">拥抱开源，快乐分享</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://movie0125.gitee.io/2021/05/13/lfs-notebook-03/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Movie">
      <meta itemprop="description" content="学习，记录，分享，收获">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Movie Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          lfs-notebook-03
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-05-13 08:59:57 / 修改时间：10:43:26" itemprop="dateCreated datePublished" datetime="2021-05-13T08:59:57+08:00">2021-05-13</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">学习笔记</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/05/13/lfs-notebook-03/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/05/13/lfs-notebook-03/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="LFS学习笔记（三）"><a href="#LFS学习笔记（三）" class="headerlink" title="LFS学习笔记（三）"></a>LFS学习笔记（三）</h1><a id="more"></a>

<h2 id="安装Linux-5-2-8-API-头文件"><a href="#安装Linux-5-2-8-API-头文件" class="headerlink" title="安装Linux-5.2.8 API 头文件"></a>安装Linux-5.2.8 API 头文件</h2><p>Linux 内核需要展示供系统 C 库（在 LFS 中是 Glibc）使用的应用程序编程接口（API）。这通过在 Linux 内核源代码 tar 包中包括一些 C 头文件来完成。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$LFS</span>/sources/build</span><br><span class="line">tar xf ../linux-5.2.8.tar.xz</span><br><span class="line"><span class="built_in">cd</span> linux-5.2.8</span><br><span class="line"></span><br><span class="line"><span class="comment">#确认这里没有陈旧的文件且不依赖于之前的操作：</span></span><br><span class="line">make mrproper</span><br><span class="line"></span><br><span class="line"><span class="comment">#从源代码中提取用户可见的内核头文件。把他们保存在一个临时本地文件夹中然后复制到所需的位置，因为解压过程会移除目标文件夹中任何已有的文件。</span></span><br><span class="line">make INSTALL_HDR_PATH=dest headers_install</span><br><span class="line">cp -rv dest/include/* /tools/include</span><br></pre></td></tr></table></figure>
<h2 id="编译-Glibc-2-30"><a href="#编译-Glibc-2-30" class="headerlink" title="编译 Glibc-2.30"></a>编译 Glibc-2.30</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> <span class="variable">$LFS</span>/sources/build</span><br><span class="line">tar xf ../glibc-2.30.tar.xz</span><br><span class="line"><span class="built_in">cd</span> glibc-2.30</span><br><span class="line">mkdir build</span><br><span class="line"><span class="built_in">cd</span> build</span><br><span class="line">../configure                             \</span><br><span class="line">      --prefix=/tools                    \</span><br><span class="line">      --host=<span class="variable">$LFS_TGT</span>                    \</span><br><span class="line">      --build=$(../scripts/config.guess) \</span><br><span class="line">      --enable-kernel=3.2                \</span><br><span class="line">      --with-headers=/tools/include</span><br><span class="line"></span><br><span class="line">make -j2</span><br><span class="line">make install</span><br></pre></td></tr></table></figure>
<h3 id="检查工具链"><a href="#检查工具链" class="headerlink" title="检查工具链"></a>检查工具链</h3><p>到这里需要检查编译工具链是否能正常工作</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;int main()&#123;&#125;&#x27;</span> &gt; dummy.c</span><br><span class="line"><span class="variable">$LFS_TGT</span>-gcc dummy.c</span><br><span class="line">readelf -l a.out | grep <span class="string">&#x27;: /tools&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#执行结果</span></span><br><span class="line"><span class="comment">#$ readelf -l a.out | grep &#x27;: /tools&#x27;</span></span><br><span class="line">      [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]</span><br><span class="line"></span><br><span class="line"><span class="comment">#清理测试文件</span></span><br><span class="line">rm -v dummy.c a.out</span><br></pre></td></tr></table></figure>

<h2 id="编译GCC-9-2-0-中的-Libstdc"><a href="#编译GCC-9-2-0-中的-Libstdc" class="headerlink" title="编译GCC-9.2.0 中的 Libstdc++"></a>编译GCC-9.2.0 中的 Libstdc++</h2><p>Libstdc++ 是标准的 C++ 库。需要用它来编译 C++ 代码（GCC 的一部分是用 C++ 写的），但是在构建 gcc-第 1 遍 时，我们需要推迟它的安装进程，因为依赖的 glibc，还未部署在 /tools 目录中。</p>
<p>Libstdc++ 是标准的 C++ 库。g++ 编译器正确运行需要它。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#进入gcc源码目录</span></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$LFS</span>/sources/build/gcc</span><br><span class="line"><span class="comment">#创建独立编译目录</span></span><br><span class="line">mkdir libstd-build</span><br><span class="line"><span class="built_in">cd</span> libstd-build</span><br><span class="line"></span><br><span class="line">../libstdc++-v3/configure           \</span><br><span class="line">    --host=<span class="variable">$LFS_TGT</span>                 \</span><br><span class="line">    --prefix=/tools                 \</span><br><span class="line">    --disable-multilib              \</span><br><span class="line">    --disable-nls                   \</span><br><span class="line">    --disable-libstdcxx-threads     \</span><br><span class="line">    --disable-libstdcxx-pch         \</span><br><span class="line">    --with-gxx-include-dir=/tools/<span class="variable">$LFS_TGT</span>/include/c++/9.2.0</span><br><span class="line"></span><br><span class="line">make -j2</span><br><span class="line">make install</span><br></pre></td></tr></table></figure>

<h2 id="Binutils-2-32-第-2-遍"><a href="#Binutils-2-32-第-2-遍" class="headerlink" title="Binutils-2.32 - 第 2 遍"></a>Binutils-2.32 - 第 2 遍</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#再次新建一个单独的编译文件夹</span></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$LFS</span>/sources/build/binutils</span><br><span class="line">mkdir build2</span><br><span class="line"><span class="built_in">cd</span> build2</span><br><span class="line"></span><br><span class="line">CC=<span class="variable">$LFS_TGT</span>-gcc                \</span><br><span class="line">AR=<span class="variable">$LFS_TGT</span>-ar                 \</span><br><span class="line">RANLIB=<span class="variable">$LFS_TGT</span>-ranlib         \</span><br><span class="line">../configure                   \</span><br><span class="line">    --prefix=/tools            \</span><br><span class="line">    --disable-nls              \</span><br><span class="line">    --disable-werror           \</span><br><span class="line">    --with-lib-path=/tools/lib \</span><br><span class="line">    --with-sysroot</span><br><span class="line"></span><br><span class="line">make -j2</span><br><span class="line">make install</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#准备链接器：</span></span><br><span class="line"><span class="comment"># 告诉 make 程序移除所有 ld 子目录中编译过的文件。</span></span><br><span class="line">make -C ld clean</span><br><span class="line"></span><br><span class="line">make -C ld LIB_PATH=/usr/lib:/lib</span><br><span class="line">cp -v ld/ld-new /tools/bin</span><br></pre></td></tr></table></figure>
<h2 id="GCC-9-2-0-第-2-遍"><a href="#GCC-9-2-0-第-2-遍" class="headerlink" title="GCC-9.2.0 - 第 2 遍"></a>GCC-9.2.0 - 第 2 遍</h2><p>我们第一次编译 GCC 的时候安装了一些内部系统头文件。其中的一个 limits.h 会反过来包括对应的系统头文件 limits.h，在我们的例子中，是 /tools/include/limits.h 。但是，第一次编译 gcc 的时候 /tools/include/limits.h 并不存在，因此 GCC 安装的内部头文件只是部分的自包含文件，并不包括系统头文件的扩展功能。这足以编译临时 libc，但是这次编译 GCC 要求完整的内部头文件。使用和正常情况下 GCC 编译系统使用的相同的命令创建一个完整版本的内部头文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> <span class="variable">$LFS</span>/sources/build/gcc/</span><br><span class="line">cat gcc/limitx.h gcc/glimits.h gcc/limity.h &gt; \</span><br><span class="line">  `dirname $(<span class="variable">$LFS_TGT</span>-gcc -print-libgcc-file-name)`/include-fixed/limits.h</span><br></pre></td></tr></table></figure>
<p>再一次更改 GCC 的默认动态链接器的位置，使用安装在 /tools 的那个。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> file <span class="keyword">in</span> gcc/config/&#123;linux,i386/linux&#123;,64&#125;&#125;.h</span><br><span class="line"><span class="keyword">do</span></span><br><span class="line">  cp -uv <span class="variable">$file</span>&#123;,.orig&#125;</span><br><span class="line">  sed -e <span class="string">&#x27;s@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g&#x27;</span> \</span><br><span class="line">      -e <span class="string">&#x27;s@/usr@/tools@g&#x27;</span> <span class="variable">$file</span>.orig &gt; <span class="variable">$file</span></span><br><span class="line">  <span class="built_in">echo</span> <span class="string">&#x27;</span></span><br><span class="line"><span class="string">#undef STANDARD_STARTFILE_PREFIX_1</span></span><br><span class="line"><span class="string">#undef STANDARD_STARTFILE_PREFIX_2</span></span><br><span class="line"><span class="string">#define STANDARD_STARTFILE_PREFIX_1 &quot;/tools/lib/&quot;</span></span><br><span class="line"><span class="string">#define STANDARD_STARTFILE_PREFIX_2 &quot;&quot;&#x27;</span> &gt;&gt; <span class="variable">$file</span></span><br><span class="line">  touch <span class="variable">$file</span>.orig</span><br><span class="line"><span class="keyword">done</span></span><br></pre></td></tr></table></figure>
<p>如果是在 x86_64 环境上构建，为 64 位库改变默认目录名至「lib」：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">case</span> $(uname -m) <span class="keyword">in</span></span><br><span class="line">  x86_64)</span><br><span class="line">    sed -e <span class="string">&#x27;/m64=/s/lib64/lib/&#x27;</span> \</span><br><span class="line">        -i.orig gcc/config/i386/t-linux64</span><br><span class="line">  ;;</span><br><span class="line"><span class="keyword">esac</span></span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">mkdir gcc-build2</span><br><span class="line"><span class="built_in">cd</span> gcc-build2</span><br><span class="line"></span><br><span class="line">CC=<span class="variable">$LFS_TGT</span>-gcc                                    \</span><br><span class="line">CXX=<span class="variable">$LFS_TGT</span>-g++                                   \</span><br><span class="line">AR=<span class="variable">$LFS_TGT</span>-ar                                     \</span><br><span class="line">RANLIB=<span class="variable">$LFS_TGT</span>-ranlib                             \</span><br><span class="line">../configure                                       \</span><br><span class="line">    --prefix=/tools                                \</span><br><span class="line">    --with-local-prefix=/tools                     \</span><br><span class="line">    --with-native-system-header-dir=/tools/include \</span><br><span class="line">    --enable-languages=c,c++                       \</span><br><span class="line">    --disable-libstdcxx-pch                        \</span><br><span class="line">    --disable-multilib                             \</span><br><span class="line">    --disable-bootstrap                            \</span><br><span class="line">    --disable-libgomp</span><br><span class="line"></span><br><span class="line">make -j2</span><br><span class="line">make install</span><br><span class="line"></span><br><span class="line"><span class="comment">#作为画龙点睛，这里创建一个符号链接。很多程序和脚本执行 cc 而不是 gcc 来保证程序的通用性，并且在所有的 Unix 类型的系统上都能用，而非仅局限于安装了 GCC 的 Unix 类型的系统。运行 cc 使得系统管理员不用考虑要安装那种 C 编译器：</span></span><br><span class="line"></span><br><span class="line">ln -sv gcc /tools/bin/cc</span><br><span class="line"></span><br><span class="line"><span class="comment">#停下来确认新工具链的基本功能（编译和链接）都是像预期的那样正常工作。运行下面的命令进行全面的检查：</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;int main()&#123;&#125;&#x27;</span> &gt; dummy.c</span><br><span class="line">cc dummy.c</span><br><span class="line">readelf -l a.out | grep <span class="string">&#x27;: /tools&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#输出形式会是：</span></span><br><span class="line">    [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]</span><br><span class="line"></span><br><span class="line"><span class="comment">#清理测试文件：</span></span><br><span class="line">rm -v dummy.c a.out</span><br><span class="line"></span><br></pre></td></tr></table></figure>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/LFS/" rel="tag"># LFS</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/05/11/lfs-notebook-02/" rel="prev" title="lfs-notebook-02">
      <i class="fa fa-chevron-left"></i> lfs-notebook-02
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/05/18/lfs-notebook-04/" rel="next" title="lfs-notebook-04">
      lfs-notebook-04 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#LFS%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%EF%BC%88%E4%B8%89%EF%BC%89"><span class="nav-number">1.</span> <span class="nav-text">LFS学习笔记（三）</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85Linux-5-2-8-API-%E5%A4%B4%E6%96%87%E4%BB%B6"><span class="nav-number">1.1.</span> <span class="nav-text">安装Linux-5.2.8 API 头文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BC%96%E8%AF%91-Glibc-2-30"><span class="nav-number">1.2.</span> <span class="nav-text">编译 Glibc-2.30</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A3%80%E6%9F%A5%E5%B7%A5%E5%85%B7%E9%93%BE"><span class="nav-number">1.2.1.</span> <span class="nav-text">检查工具链</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BC%96%E8%AF%91GCC-9-2-0-%E4%B8%AD%E7%9A%84-Libstdc"><span class="nav-number">1.3.</span> <span class="nav-text">编译GCC-9.2.0 中的 Libstdc++</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Binutils-2-32-%E7%AC%AC-2-%E9%81%8D"><span class="nav-number">1.4.</span> <span class="nav-text">Binutils-2.32 - 第 2 遍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GCC-9-2-0-%E7%AC%AC-2-%E9%81%8D"><span class="nav-number">1.5.</span> <span class="nav-text">GCC-9.2.0 - 第 2 遍</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Movie</p>
  <div class="site-description" itemprop="description">学习，记录，分享，收获</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">14</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Movie</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>











<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'bx3R5BB7VYCe0Yu5f4PF2Ako-gzGzoHsz',
      appKey     : '24eOkgM1v8hYTlnAO3C2eG3n',
      placeholder: "欢迎留言评论",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
